﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Gateway.Interfaces.DTO;

namespace PServiceBus.Gateway.Interfaces {
    public class ESBGateway {
        private static List<RouterInfo> _routerAddresses = new List<RouterInfo>();
        public static ESBEndpoint LastEndpoint { get; set; }
        public static Action ReconnectCallback { get; set; }

        public static List<RouterInfo> RouterAddresses {
            get { return _routerAddresses; }
        }

        public static void AddRouterAddress(string endpoint) {
            if (_routerAddresses.Any(router => router.Endpoint == endpoint)) return;
            var tokens = endpoint.Split(':');
            tokens[0] = "endpoint";
            endpoint = String.Join(":", tokens);
            _routerAddresses.Add(
                new RouterInfo()
                {
                    Endpoint = endpoint,
                    IsAvailable = true
                });
        }
    }
}
